package com.controller.content;

import com.dto.BusinessDto;
import com.pojo.Member;
import com.pojo.Page;
import com.service.MemberService;
import com.service.OrdersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Resource
    private OrdersService ordersService;
    @Resource
    private MemberService memberService;

    @RequestMapping
    public String search(Model model, Member member, @RequestParam(value = "pageIndex", required = false)Integer pageIndex) {
        Page page=new Page();
        page.setCurrentPage(pageIndex!=null ? pageIndex:1);
        Long memberId = memberService.getIdByPhone(member.getPhone());
        model.addAttribute("list", ordersService.getListByMemberId(memberId != 0 ? memberId:null, page));
        member.setPage(page);
        model.addAttribute("searchParam", member);
        return "/content/orderList";
    }

}
